import Vue from 'vue'
import bus from '@/components/storybook/utilties/bus'
import { GlobalTimeformat } from '@/utils/common'


export const LinkedBotsActionTemplate = Vue.component('LinkedBotsActionTemplate', {
  template:
    `
      <div class="flex items-center">
        <el-button plain size="mini" type="primary" @click="onView" >View</el-button>
        <el-button plain size="mini" type="danger" @click="onDelete" v-if="$hasPermission('sys:bots:delete')">Delete</el-button>
      </div>
    `,
  methods: {
    onView () {
      bus.$emit('event:view-linked-bot', this.$data.data)
    },
    onDelete () {
      bus.$emit('event:delete-linked-bot', this.$data.data)
    }
  }
})

export const TimeFormatTemplate = Vue.component('TimeFormatTemplate', {
  template:
    `
      <span>
        {{timeformat($data.data.updateTime||$data.data.updateDate)}}
      </span>
    `,
  methods: {
    timeformat (time) {
      return GlobalTimeformat(time, 'HH:mm')
    }
  }
})



export const RenderLinkedBotsAction = () => {
  return {
    template: LinkedBotsActionTemplate
  }
}

export const RenderTimeFormat = () => {
  return {
    template: TimeFormatTemplate
  }
}
